package com.ilancuo.proxy;

import java.lang.reflect.Proxy;
import java.util.Arrays;

/**
 * 测试代理方法
 * <p>
 * Created by ilancuo on 13/03/2018.
 */
public class Test {

    public static void main(String[] args) {
        IUser user = (IUser) Proxy.newProxyInstance(IUser.class.getClassLoader(), new Class[]{IUser.class}, (proxy, method, args1) -> {
            System.out.println("Method: " + method.getName() + ", Params: " + Arrays.toString(args1));
            switch (method.getName()) {
                case "login":
                    break;
                case "logout":
                    return "logout success";
            }
            return null;
        });
        user.login("ilancuo", "jjfly555");
        String result = user.logout();
        System.out.println(result);
    }
}
